package dk.itu.mobile.vo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.xml.bind.annotation.XmlRootElement;


/**
 * @author jacobbj
 *
 */
@XmlRootElement(name = "Envelope")
public class Envelope implements Serializable {

	private static final long serialVersionUID = 1L;

	public String command;
	
	public String type;
	
	public String username;
	public String password;
	
	public String id;
	public String taskname;
	public Date date;
	public Status status;
	public String description;
	public String attendants;
	
	public Envelope() {
		// Empty constructor for marshalling
	}

	public Envelope(String command, User user) {
		this.command = command;
		this.type = "userjob";
		this.username = user.name;
		this.password = user.password;
	}
	
	public Envelope(String command, Task task) {
		this.command = command;
		this.type = "taskjob";
		this.id = task.id;
		this.taskname = task.name;
		this.date = task.date;
		this.status = task.status;
		this.description = task.description;
		
		List<User> userlist = (ArrayList<User>)task.getUsers();
		this.attendants = "";
		for (User u : userlist) this.attendants += u.name + ",";
	}

	public boolean equals(Object other) {
		if (this == other) {
			return true;
		} else if (other instanceof Envelope) {
			Envelope otherJob = (Envelope) other;
			if (this.command.equals(otherJob.command)) {
				return true;
			}
		}
		return false;
	}
	
	public String toString() {
		
		String value = "Envelope: \n";
		value += "command: " + command + "\n";
		value += "type: " + type + "\n";
		value += "username: " + username + "\n";
		value += "password: " + password + "\n";
		value += "taskname:" + taskname + "\n";
		value += "task-id: " + id + "\n";
		value += "date: " + date + "\n";
		value += "description:" + description + "\n";
		value += "attendants: " + attendants + "\n";
				
		return value;
	}
}